should look similar to a native file object."""
raise RuntimeError, "open_file not implemented"
-
+ def file_exist(self, file):
+ """Check to see if the give file is existed.
+ Return true if file existed, return false otherwise."""
+ raise RuntimeError, "file_exist not implemented"
mydir = sys.modules['grub.fsys'].__path__[0]
for f in os.listdir(mydir):
return (PyObject *) file;
}
+static PyObject *
+ext2_file_exist (Ext2Fs *fs, char * name)
+{
+ int err;
+ ext2_ino_t ino;
+ Ext2File * file;
+
+ file = (Ext2File *) PyObject_NEW(Ext2File, &Ext2FileType);
+ file->file = NULL;
+
+ err = ext2fs_namei_follow(fs->fs, EXT2_ROOT_INO, EXT2_ROOT_INO, name, &ino);
+ if (err) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ Py_INCREF(Py_True);
+ return Py_True;
+}
+
/* ext2fs object */
static PyObject *
return ext2_file_open(fs, name, flags);
}
+static PyObject *
+ext2_fs_file_exist (Ext2Fs *fs, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "name", NULL };
+ char * name;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &name))
+ return NULL;
+
+ return ext2_file_exist(fs, name);
+}
+
static void
ext2_fs_dealloc (Ext2Fs * fs)
{
{ "open_file",
(PyCFunction) ext2_fs_open_file,
METH_VARARGS|METH_KEYWORDS, NULL },
+ { "file_exist",
+ (PyCFunction) ext2_fs_file_exist,
+ METH_VARARGS|METH_KEYWORDS, NULL },
{ NULL, NULL, 0, NULL }
};
return (PyObject *)pfs;
}
-
static struct PyMethodDef Ext2ModuleMethods[] = {
{ "Ext2Fs", (PyCFunction) ext2_fs_new, METH_VARARGS|METH_KEYWORDS, NULL },
{ NULL, NULL, 0, NULL }
};
-
void init_pyext2(void) {
- PyObject *m, *d;
+ PyObject *m;
m = Py_InitModule("_pyext2", Ext2ModuleMethods);
- d = PyModule_GetDict(m);
-
- /* o = PyObject_NEW(PyObject, yExt2FsConstructorType);
- PyDict_SetItemString(d, "PyExt2Fs", o);
- Py_DECREF(o);*/
-
+ /*
+ * PyObject *d;
+ * d = PyModule_GetDict(m);
+ * o = PyObject_NEW(PyObject, yExt2FsConstructorType);
+ * PyDict_SetItemString(d, "PyExt2Fs", o);
+ * Py_DECREF(o);
+ */
}
import curses, _curses, curses.wrapper
import getopt
+sys.path = [ '/usr/lib/python' ] + sys.path
+
import grub.GrubConf
import grub.fsys
if len(buf) >= 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaaff):
return True
return False
-
def get_config(fn):
if not os.access(fn, os.R_OK):
break
if fs is not None:
- f = fs.open_file("/boot/grub/grub.conf")
+ if fs.file_exist("/boot/grub/menu.lst"):
+ grubfile = "/boot/grub/menu.lst"
+ elif fs.file_exist("/boot/grub/grub.conf"):
+ grubfile = "/boot/grub/grub.conf"
+ else:
+ raise RuntimeError, "we couldn't find /boot/grub{menu.lst,grub.conf} " + \
+ "in the image provided. halt!"
+ f = fs.open_file(grubfile)
buf = f.read()
f.close()
fs.close()